/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.recommend;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.recommend.HkLoveSeeRecommend;
import com.thinkgem.jeesite.modules.hk.sys.service.recommend.HkLoveSeeRecommendService;

/**
 * 热门推荐Controller
 * @author 罗天文
 * @version 2018-05-10
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/recommend/hkLoveSeeRecommend")
public class HkLoveSeeRecommendController extends BaseController {

	@Autowired
	private HkLoveSeeRecommendService hkLoveSeeRecommendService;
	
	@ModelAttribute
	public HkLoveSeeRecommend get(@RequestParam(required=false) String id) {
		HkLoveSeeRecommend entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkLoveSeeRecommendService.get(id);
		}
		if (entity == null){
			entity = new HkLoveSeeRecommend();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:recommend:hkLoveSeeRecommend:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkLoveSeeRecommend hkLoveSeeRecommend, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkLoveSeeRecommend> page = hkLoveSeeRecommendService.findPage(new Page<HkLoveSeeRecommend>(request, response), hkLoveSeeRecommend); 
		model.addAttribute("page", page);
		return "hk/sys/recommend/hkLoveSeeRecommendList";
	}

	@RequiresPermissions("sys:recommend:hkLoveSeeRecommend:view")
	@RequestMapping(value = "form")
	public String form(HkLoveSeeRecommend hkLoveSeeRecommend, Model model) {
		model.addAttribute("hkLoveSeeRecommend", hkLoveSeeRecommend);
		return "hk/sys/recommend/hkLoveSeeRecommendForm";
	}

	@RequiresPermissions("sys:recommend:hkLoveSeeRecommend:edit")
	@RequestMapping(value = "save")
	public String save(HkLoveSeeRecommend hkLoveSeeRecommend, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkLoveSeeRecommend)){
			return form(hkLoveSeeRecommend, model);
		}
		hkLoveSeeRecommendService.save(hkLoveSeeRecommend);
		addMessage(redirectAttributes, "保存热门推荐成功");
		return "redirect:"+Global.getAdminPath()+"/sys/recommend/hkLoveSeeRecommend/?repage";
	}
	
	@RequiresPermissions("sys:recommend:hkLoveSeeRecommend:edit")
	@RequestMapping(value = "delete")
	public String delete(HkLoveSeeRecommend hkLoveSeeRecommend, RedirectAttributes redirectAttributes) {
		hkLoveSeeRecommendService.delete(hkLoveSeeRecommend);
		addMessage(redirectAttributes, "删除热门推荐成功");
		return "redirect:"+Global.getAdminPath()+"/sys/recommend/hkLoveSeeRecommend/?repage";
	}

}